package com.yhgm.utils.timer;

import com.yhgm.mapper.FileDeleteDao;
import org.quartz.Job;
import org.quartz.JobExecutionContext;

import javax.annotation.Resource;
import java.io.File;
import java.util.Date;
import java.util.List;

public class FileDeleteJob implements Job {
    @Resource
    private FileDeleteDao fileDeleteJobDao;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        Date date = new Date(System.currentTimeMillis());
        List<String> paths = fileDeleteJobDao.getPathsByTime(date);
        for (String path : paths) {
            File file = new File(path);
            if (file.exists()) {
                file.delete();
            }
        }
        fileDeleteJobDao.deletePathsByTime(date);
    }
}
